<?php
// print_r($_GET); die; 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

// normal page 

get_header();
?>
<!-- Menu các trang ảnh cưới  -->
<?php get_sidebar('anhcuoi') ?>
<!-- End menu ảnh cưới -->

<script src="<?php echo bloginfo('template_url'); ?>/js/jquery.masonry.min.js" type="text/javascript"></script>
<script src="<?php echo bloginfo('template_url'); ?>/js/jquery.infinitescroll.js" type="text/javascript"></script>
<style type="text/css">
    #layout-demo .item {
        margin: 4px;
    }
    #layout-demo .masonry {
        margin: 0 auto;
    }
    #infscr-loading {
        position: absolute;
        bottom: 10%;
        left: 49%;
    }

</style>
<div id="layout-demo">
    <div id="container" class="masonry clickable" >
        <?php
        global $wpdb;
        //Sets the number of images to display
        $limit = 12;
        //Sets the width and1height of each image
        $width = 210;
		
		$user_ID = get_current_user_id();

		$thumb_path = my_get_home_path() . "/media/user_{$user_ID}/all/thumbs/";

		$allthumbs = scandir($thumb_path);
	
		foreach($allthumbs as $key=>$value){
			if($key == 0  || $key == 1 ) unset($allthumbs[$key]);
		}
		$allthumbs = array_values($allthumbs);

        if (is_array($allthumbs)) {
            foreach ($allthumbs as $k => $pix) {
                $imgurl = get_site_url() . "/media/user_{$user_ID}/all/thumbs/" . $row;
                $class = ''; //$k%2 ?  'w2' : ''; 
                echo '<div class="item ' . $class . '"><img height="auto" width="' . $width . '" src="' . $imgurl . '"  alt="' . $pix->alttext . '" /></div>';
            }
        }
        ?>
    </div>
</div>
<nav id="page-nav">
    <a href="<?php echo site_url() ?>/gallery-page-2.html"></a>
</nav>

<script type type="text/javascript">
    $(function() {

        var $container = $('#container');

        $container.imagesLoaded(function() {
            $container.masonry({
                itemSelector: '.item',
                gutter: 10
            });
        });

        $container.infinitescroll({
            navSelector: '#page-nav', // selector for the paged navigation
            nextSelector: '#page-nav a', // selector for the NEXT link (to page 2)
            itemSelector: '.item', // selector for all items you'll retrieve
            loading: {
                finishedMsg: 'No more pages to load.',
                img: 'http://i.imgur.com/6RMhx.gif'
            }
        },
        // trigger Masonry as a callback
        function(newElements) {
            // hide new items while they are loading
            var $newElems = $(newElements).css({opacity: 0});
            // ensure that images load before adding to masonry layout
            $newElems.imagesLoaded(function() {
                // show elems now they're ready
                $newElems.animate({opacity: 1});
                $container.masonry('appended', $newElems, true);
            });
        }
        );

    });
</script>
<?php get_footer(); ?>
